package chat.client;

import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.net.Socket;
import java.util.*;

import chat.*;
import chat.user.Group;
import chat.user.Message;

public class ClientReceiver implements Runnable{
	
	private Socket socket;
	private ObjectInputStream ois;
	private Object input;
	private ClientRequestor client_requestor;
	
	public ClientReceiver(Socket s) {
		
		socket = s;
		
		//start();
	}
	
	@Override
	public void run(){
		
		try{
			
			while(true){
				
				ois = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
				
				Message m = (Message) ois.readObject();
				
				ClientMain.addInMessage(m);
				
				/*if (m.GROUP_UPDATE){
				
					LinkedList<Group> gf = m.getGroupList();
					
					for (Group p: gf){
						
						if (!p.getName().equalsIgnoreCase("ROOT")){
						
							client_requestor.getChat().addNewItem(p.getName());
						}
					}*/
				
				/*	Is not used now
				 * 
				 * if (m.AUTH_REQUEST){
						
						client_requestor.AuthMessage();
					}*/
				}
			
		}
		catch(IOException e){e.printStackTrace();
			
		}
		catch(ClassNotFoundException e){
			e.printStackTrace();
		}
	}
}
